<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/5/23
  Time: 11:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8" />
    <title>作品 | 作品名称</title><!-- 显示作品的具体名称-->
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font-awesome.min.css" type="text/css" />

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css" type="text/css" />
    <style>
        hr{
            margin-top: 0px;
        }
    </style>
</head>
<body style="overflow-x: hidden;overflow-y: hidden;height: 250px">
    <div style="padding: 20px 20px ">
        <!-- 新建一条评论 -->
        <h4 class="m-t-lg m-b" style="">
            <i class="fa fa-sign-language" aria-hidden="true"></i>
            新建评论
        </h4>
        <HR style="border:1 dashed #987cb9" width="100%" color=#987cb9 SIZE=1>

        <div class="form-group">
            <textarea class="form-control" rows="5" placeholder="输入..." id="content"></textarea>
        </div>
        <div class="form-group">
            <button id="addComment" class="btn btn-success" style="margin-top:10px;height: 30px;width: 100px;background-color: #17a05a;border-color: #159253;">发表</button>
        </div>
        <!-- ／新建一条评论 -->
    </div>
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/layer/layer.js"></script>
    <script>
        $("#addComment").click(function () {
            var content=$("#content").val();
            if (content==""){
                layer.msg('请输入您的评论！', {time: 3000, icon:5});
                return false;
            }
            var articleId=getQueryString("articleId");
            //alert(articleId);
            var regInfo={
                articleId:articleId,
                content:content,
                parentId:getQueryString("parentId")
            };
            $.ajax({
                contentType:"application/json",
                url:getRootPath()+"/comment/add",
                type:"post",
                dataType:"json",
                data:JSON.stringify(regInfo),
                success:function (data) {
                    if (data.res==0){
                        layer.msg(data.msg, {time: 3000, icon:2});
                    }else {
                        layer.msg(data.msg, {time: 3000, icon:6});
                        setTimeout(function () {
                            window.parent.location.reload();
                        },1000);
                    }

                },
                error:function (error) {
                    layer.msg('连接失败！', {time: 3000, icon:5});
                }

            });
        });

        function getRootPath() {
            var curWwwPath = window.document.location.href;
            var pathName = window.document.location.pathname;
            var pos = curWwwPath.indexOf(pathName);
            var localhostPaht = curWwwPath.substring(0, pos);
            var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
            return (localhostPaht + projectName);
        }

        // 获取url的参数
        function getQueryString(name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]); return null;
        }
    </script>

</body>
</html>
